<?php
include_once('common/header.php');
if(!isset($_SERVER['HTTP_REFERER'])) {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intAction 	= $objRequest->getParam('act',null);
$intNewsId 	= $objRequest->getParam('newsid',null);
$intError	= 0;
$objNews 	= new News();
$strMessage	= '';
$intLike	= 0;
if(isset($intAction)) {
	if($intAction == 1) {
		if($AppUI->id > 0) {
			$intError = $objNews->addLike($AppUI->id, $intNewsId, $intLike);		
			if($intError > 0) $intError += 17;
			else $strMessage = $arrMessage[11];
		} else {
			$intError = 1;
		}

	}elseif($intAction == 2) {
		if($AppUI->id > 0) {
			$intError = $objNews->delete($AppUI->id,$intNewsId);		
			if($intError > 0) $intError = 4; 
			$strMessage = $arrMessage[10];
		} else {
			$intError = 1;
		}
	}elseif($intAction == 3) {
		if($AppUI->id > 0) {
			$strImage = '';
			$intError = $objNews->updateImg($AppUI->id, $intNewsId, $strImage);
			if($intError == 0) {
				$objNews->deleteImg(0, $strImage);
				$strMessage = $arrMessage[3];
			} else $intError = 5; 				
		} else {
			$intError = 1;
		}
	}elseif($intAction == 4) {	
		if($AppUI->id > 0) {
			include_once('index/box-news.php');
			$this->view->ajax	= 1;
			$objView		= Zend_Registry::get('objView');			
			$strHeader		= $objView->fetch('index/box-news-header.tpl');
			$strNews		= $objView->fetch('index/box-news.tpl');
			$arrJson		= array('error'		=> 0, 	
									'dnews' 	=> $strNews,
									'dheader' 	=> $strHeader,
									);
			echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';	
			exit();
		} else {
			$intError = 1;
		}
	}elseif($intAction == 5) {
		$intAjax			= 1;
		include_once('new/list.php');
		$this->view->ajax	= $intAjax;
		$objView			= Zend_Registry::get('objView');			
		$strNews			= $objView->fetch('new/box-list-item.tpl');
		$arrJson			= array('error'		=> 0, 	
									'dnews' 	=> $strNews
								);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';	
		exit();
	}elseif($intAction == 6) {
		$intAjax			= 1;
		include_once('new/search.php');
		$this->view->ajax	= $intAjax;
		$objView			= Zend_Registry::get('objView');			
		$strNews			= $objView->fetch('new/box-list-item.tpl');
		$arrJson			= array('error'		=> 0, 	
									'dnews' 	=> $strNews
								);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';	
		exit();
	}
}	
if($intError == 0) {
	if($intAction == 1) {
		$arrJson	= array('error'=>0,'msg'=>$strMessage,'like'=>Vfriend_Function::numberFormat($intLike));
	} elseif($intAction > 1) {		
		$arrJson	= array('error'=>0,'msg'=>$strMessage);
	}
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	
} else {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[$intError]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
}
exit();
?>
